package com.hd.crdao.factory;

import android.support.v4.app.Fragment;

import java.util.HashMap;
import java.util.Map;

/**
 *
 *@author Programming
 *@date 2017/6/28 0028
 */

public class FragmentFactory {
    private FragmentFactory() {

    }

    private static Map<Class, Fragment> map = new HashMap<>();

    public static synchronized Fragment getInstance(Class<? extends Fragment> clazz) {
        Fragment fragment = map.get(clazz);
        if (fragment == null) {
            try {
                fragment = clazz.newInstance();
                map.put(clazz, fragment);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        return fragment;
    }
}